
Component({
    /**
     * 组件的属性列表
     */
    properties: {
        list: {
            type: Array,
            value: []
        }
    },

    /**
     * 组件的初始数据
     */
    data: {
        list: [],
        tabIndex: 0,
        width: 0,
        leftOffset: 10,
    },
    lifetimes: {
		attached: function() {
            
		},
		ready: function () {
            this.fnInit();
		},
	},

    /**
     * 组件的方法列表
     */
    methods: {
        fnInit: function () {
            let list = this.properties.list;
            if (list.length <= 0) {
                list = ['全部', '待取货', '配送中', '已完成', '已取消'];   
            }
			// 计算宽度
            let len = list.length;
            let width = 100 / len;
            
            this.setData({list, width});
        },

        fnTabClick: function (e) {
            let {index} = e.currentTarget.dataset;
            let {width, tabIndex} = this.data;
            // 重复点击
            if (index === tabIndex) {
                return;
            }
            // 计算偏移值
            let leftOffset = width * index + 10;
            this.setData({leftOffset, tabIndex: index});

            // 注册事件
            this.triggerEvent('fnGetIndex', { index }, {});
        },
    }
})
